/**
 * @name: shuiwuReservoirScreenStore
 * @author: yuyy
 * @date: 2023/4/11 15:06
 * @description：水库大屏本地化管理
 * @update: 2023/4/11 15:06
 */
import pinia from './index';
import { defineStore } from 'pinia';

export const demoStore = defineStore('demoStore', {
  state: () => {
    // @ts-ignore
    return {
      demoData: null,
      appCount: 0
    };
  },
  getters: {
    getdemoData(state) {
      return state.demoData;
    }
  },
  actions: {
    setdemoData(data: any) {
      this.demoData = data;
    },
    add() {
      this.appCount++;
    }
  },
  // 开启数据缓存, 需要确保插件pinia-plugin-persist已安装
  persist: {
    enabled: true,
    strategies: [
      {
        // key: "lowCode", // key可以自己定义，不填的话默认就是这个store的ID
        storage: localStorage, // storage可以填sessionStorage，localStorage
        paths: ['demoData'] // paths是需要存储的字段，不填就是全部
      }
    ]
  }
});

// 组件外定义
export const usedemoStore = () => {
  return demoStore(pinia);
};
